#!/usr/bin/env python
#Boa:PyApp:main

import wx
#import wx.images
from wx.lib.wordwrap import wordwrap
import wx.lib.buttonpanel as bp
import wx.gizmos as gizmos

# Const Variables
#   Menu ID
id_menuGame_Start = wx.NewId()
id_menuGame_Close = wx.NewId()
id_menuGame_Beginner = wx.NewId()
id_menuGame_Middle = wx.NewId()
id_menuGame_Expert = wx.NewId()
id_menuGame_Custom = wx.NewId()
id_menuGame_Record = wx.NewId()
id_menuGame_QuestionMark = wx.NewId()
id_menuAbout_Help = wx.NewId()
id_menuAbout_About = wx.NewId()
#   Game Level
BEGINNER = 1
MIDDLE = 2
EXPERT = 3
CUSTOM = 4


# Global Variables
StartLevel = BEGINNER



modules ={}

class PythonMineFrameClass(wx.Frame):
    def __init__(self, parent, id, title):
        #wx.Frame.__init__(self, parent, id, title, size=(300, 100), 
        #        style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.FRAME_NO_TASKBAR | wx.CLIP_CHILDREN)
        wx.Frame.__init__(self, parent, id, title, size=(300, 300))
        self.CenterOnScreen()
        #self.CreateStatusBar()
        #self.SetStatusText("This is the statusbar")
        
        
        self.InitOptions()
        
        # Setup Menu
        self.createMenu()


        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.TimeEvt)
        self.controlPanel = wx.Panel(self, -1, size=wx.Size(100, 100), pos=wx.Point(0, 0), style=wx.TAB_TRAVERSAL)
        self.minePanel = wx.Panel(self, -1, size=wx.Size(100, 100), pos=wx.Point(200, 200), style=wx.TAB_TRAVERSAL)
        #self.vSizer = wx.BoxSizer(wx.VERTICAL)
        #self.controlPanel.SetSizer(self.vSizer)
        
        self.createBar()

    # Private Function Members
    def InitOptions(self):
        self.QuestionMark = True
        self.high = 16
        self.width = 30
        self.mine = 99
        
    
    def createMenu(self):
        menuBar = wx.MenuBar()
        menuGame = wx.Menu()
        menuGame.Append(id_menuGame_Start, "&Start\tF2", "")
        self.Bind(wx.EVT_MENU, self.menuGame_Start, id=id_menuGame_Start)
        menuGame.AppendSeparator()
        menuGame.Append(id_menuGame_Beginner, "&Beginner", "", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.menuGame_Beginner, id=id_menuGame_Beginner)
        menuGame.Append(id_menuGame_Middle, "&Middle", "", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.menuGame_Middle, id=id_menuGame_Middle)
        menuGame.Append(id_menuGame_Expert, "&Expert", "", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.menuGame_Expert, id=id_menuGame_Expert)
        menuGame.Append(id_menuGame_Custom, "&Custom...", "", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.menuGame_Custom, id=id_menuGame_Custom)
        menuGame.AppendSeparator()
        menuGame.Append(id_menuGame_QuestionMark, "&Mark Question?", "", wx.ITEM_CHECK)
        #menuGame.check(id_menuGame_QuestionMark, True)
        self.Bind(wx.EVT_MENU, self.menuGame_QuestionMark, id=id_menuGame_QuestionMark)
        menuGame.AppendSeparator()
        menuGame.Append(id_menuGame_Record, "&Record...", "")
        self.Bind(wx.EVT_MENU, self.menuGame_Record, id=id_menuGame_Record)
        menuGame.AppendSeparator()
        menuGame.Append(id_menuGame_Close, "&Close\tAlt+F4", "")
        self.Bind(wx.EVT_MENU, self.menuGame_Close, id=id_menuGame_Close)
        menuBar.Append(menuGame, "&Game")
        menuAbout = wx.Menu()
        menuAbout.Append(id_menuAbout_Help, "&Help...\tF1", "")
        self.Bind(wx.EVT_MENU, self.menuAbout_Help, id=id_menuAbout_Help)
        menuAbout.AppendSeparator()
        menuAbout.Append(id_menuAbout_About, "&About...", "")
        self.Bind(wx.EVT_MENU, self.menuAbout_About, id=id_menuAbout_About)
        menuBar.Append(menuAbout, "&Help")
        self.SetMenuBar(menuBar)
        
    def createBar(self):
        #self.Freeze()
        #self.titleBar = bp.ButtonPanel(self.controlPanel, -1, "", bp.BP_USE_GRADIENT, bp.BP_ALIGN_LEFT)
        #startButton= bp.ButtonInfo(titleBar, wx.NewId(), )
        #titleBar.AddButton(startButton)
        #Bind(wx.EVT_BUTTON, self.OnButton, id=startButton.GetId())
        
        self.led = gizmos.LEDNumberCtrl(self.controlPanel, -1)
        self.led.SetValue("000")
        self.led.SetAlignment(gizmos.LED_ALIGN_RIGHT)
        self.led.SetDrawFaded(False)
        #self.vSizer.Add(self.led)
        a = wx.Button(self.controlPanel, 10, "a Button", (20, 20))
        b = wx.Button(self.controlPanel, 10, "b Button", (20, 20))
        c = wx.Button(self.controlPanel, 10, "Default Button", (20, 20))
        self.startButton = wx.BitmapButton(bitmap=wx.NullBitmap,
              id=-1, name='aabb',
              parent=self.controlPanel, pos=wx.Point(56, 56), size=wx.Size(24, 24),
              style=wx.BU_AUTODRAW)
        self.staticText1 = wx.StaticText(id=-1,
              label='staticText1', name='staticText1', parent=self.controlPanel,
              pos=wx.Point(32, 32), size=wx.Size(62, 14), style=0)
        #self.vSizer.Add(a)
        #self.vSizer.Add(b)
        #self.vSizer.Add(c)
        pass

    def startTimer(self):
        self.timer.Start(1000)
    def TimeEvt(self, evt):
        self.time = self.time + 1
        self.led.SetValue(str(self.time))

    # Menu Functions
    def menuGame_Start(self, event):
        self.time = 0
        self.startTimer()
        pass
    def menuGame_Beginner(self, event):
        StartLevel = BEGINNER
        pass
    def menuGame_Middle(self, event):
        StartLevel = MIDDLE
        pass
    def menuGame_Expert(self, event):
        StartLevel = EXPERT
        pass
    def menuGame_Custom(self, event):
        StartLevel = CUSTOM
        pass
    def menuGame_QuestionMark(self, event):
        self.QuestionMark = not self.QuestionMark
        pass
    def menuGame_Record(self, event):
        pass
    def menuGame_Close(self, event):
        wx.Exit()
    def menuAbout_Help(self, event):
        dlg = wx.MessageDialog(self, 'Help',
                               'A Message Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
        dlg.ShowModal()
        dlg.Destroy()
        pass
    def menuAbout_About(self, event):
        info = wx.AboutDialogInfo()
        info.Name = "PythonMine"
        info.Version = "0.1"
        info.Description = wordwrap(
            "\"PythonMine\" program is an Mine Game like WinMine written by wxPython",
            350, wx.ClientDC(self))
        info.WebSite = ("http://code.google.com/p/pythonmine/", "PythonMine Main Page")
        info.Developers = [ "KevinKW" ]

        info.License = wordwrap("Free! XD\n  HiaHiaHia~~~~", 500, wx.ClientDC(self))

        # Then we call wx.AboutBox giving it that info object
        wx.AboutBox(info)
  

class PythonMineAppClass(wx.App):  
    def OnInit(self):
        frame = PythonMineFrameClass(parent=None, id=-1, title="PythonMine")
        frame.Show()
        return True

def main():
    PythonMineApp = PythonMineAppClass()
    PythonMineApp.MainLoop()
    pass

if __name__ == '__main__':
    main()

